package com.opentd.gui;

import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JPanel;

import com.opentd.game.Game;
import com.opentd.graphics.screen.EndScreen;
import com.opentd.graphics.screen.GameScreen;
import com.opentd.graphics.screen.LevelSelectScreen;
import com.opentd.graphics.screen.MainScreen;

/**
 * @author Nathan Hoyt
 * Date: Oct 25, 2012
 * Desc: This class will show all of the components on the screen.
 *
 */
public class GamePanel extends JPanel{
	public GamePanel(){
		setPreferredSize(new Dimension(594, 572));
		setSize(new Dimension(594, 572));
		addMouseListener(Game.mouseListener);
		addMouseMotionListener(Game.mouseMotionListener);
	}
	/**
	 * This method will choose which screen to draw based on the games current
	 * state, and then call the draw method of that screen class.
	 * 
	 * @param g The graphics component used to draw on.
	 */
	public void paintComponent(Graphics g){
		g.clearRect(0, 0, getWidth(), getHeight());
		
		if(Game.State.currentScreen == Game.State.MAIN_SCREEN){
			MainScreen.draw(g);
		} else if(Game.State.currentScreen == Game.State.LEVEL_SELECT_SCREEN){
			LevelSelectScreen.draw(g);
		} else if(Game.State.currentScreen == Game.State.GAME_SCREEN){
			GameScreen.draw(g);
		} else if(Game.State.currentScreen == Game.State.END_SCREEN){
			EndScreen.draw(g);
		}else{
			throw new IllegalStateException("The state " + Game.State.currentScreen + " is not a valid state for the game.");
		}
	}

}
